<!-- 调用组件示例 -->
<template>
  <div style="height: 100%">
    <AHMF :asideWidth="400" :rightTitleShow="false">
      <template #aside> </template>
      <template #header>
        <topSearcher
          :searchOptions="searchOptions"
          @onQuery="onQuery"
          @onReset="onReset"
        ></topSearcher>
      </template>
      <template #main>
        <div style="margin-bottom: 10px; display: flex">
          <el-button type="primary" size="small">新增</el-button>
        </div>
        <!-- <el-table
        :data="tableData"
        border
        style="width: 100%"
        :height="tableHeight"
        v-loading="tableLoading"
        @sort-change="sortChange"
      >
        <el-table-column align="center" type="index" label="序号" width="50">
        </el-table-column>
        <template v-for="item in tableColumns">
          <el-table-column
            align="center"
            :prop="item.prop"
            :label="item.label"
            :width="item.width"
            :sortable="item.sortable"
          >
            <template slot-scope="scope">
              <span style="color: red" v-if="item.prop == 'name'">{{
                scope.row[item.prop]
              }}</span>

              <span v-else>{{ scope.row[item.prop] }}</span>
            </template>
          </el-table-column>
        </template>
      </el-table> -->
        <ETable
          :data="tableData"
          :titleObj="tableColumns"
          operateWidth="100"
          @sortFun="sortFun"
          :loading="tableLoading"
        >
          <template v-slot="{ scope }">
            <el-button @click="modifyClick(scope)" type="text" size="small"
              >修改</el-button
            >
          </template>
        </ETable>
      </template>
      <template #footer>
        <div class="flex">
          <el-pagination
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="pageInfo.currPage"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="pageInfo.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="pageInfo.total"
          >
          </el-pagination>
        </div>
      </template>
    </AHMF>
  </div>
</template>
<script>
import topSearcher from "@/components/topSearcher/topSearcher.vue";
import AHMF from "@/components/topSearcher/AHMF.vue";
import ETable from "@/components/ETable";
import {
  getSysSystemParam,
  postSysSystemParam,
  getSysSystemParamSort,
  getSysSystemParamEdit,
} from "@/api/management/parameter";
export default {
  components: {
    AHMF,
    topSearcher,
    ETable,
  },

  data() {
    return {
      //表格字段
      tableColumns: [
        {
          prop: "PARAM_CODE",
          label: "参数编号",
          width: "160",
          sortable: "custom",
        },
        {
          prop: "PARAM_NAME",
          label: "参数描述",

          sortable: "custom",
        },
        { prop: "PARAM_VALUE", label: "参数值", width: "160" },
      ],
      // 搜索字段
      searchOptions: [
        {
          type: "input",
          label: "参数名称",
          key: "paramName",
          value: "",
        },

        {
          type: "select",
          label: "启用状态",
          key: "isEnable",
          value: "",
          options: [
            { label: "已停用", value: "0" },
            { label: "已启用", value: "1" },
          ],
        },
        {
          type: "rangeInput",
          label: "发券张数",
          key1: "couNumMin",
          key2: "couNumMax",
          value1: "",
          value2: "",
        },
        {
          type: "datetimeRange",
          label: "订单时间1",
          key: "orderTime1",
          valueFormat: "yyyy-MM-dd HH:mm:ss",
          // spanPercentage: 40,
          value: ["1999-11-11 11:11:11", "1999-11-11 11:11:11"],
        },
        {
          type: "dateRange",
          label: "订单时间2",
          key: "orderTime2",
          valueFormat: "yyyy-MM-dd",
          value: [],
        },
        {
          type: "datetime",
          label: "订单时间3",
          key: "orderTime3",
          valueFormat: "yyyy-MM-dd",
          value: "",
        },
        {
          type: "date",
          label: "订单时间4",
          key: "orderTime4",
          valueFormat: "yyyy-MM-dd",
          value: "",
        },
        {
          type: "checkBox",
          label: "订单时间4",
          options: [
            {
              key: "key1",
              label: "label1",
              value: true,
              span: 8,
            },
            {
              key: "key2",
              label: "label2",
              value: true,
              span: 8,
            },
            {
              key: "key3",
              label: "label3",
              value: "",
              span: 8,
            },
          ],
        },
        {
          type: "radioGroup",
          label: "在场状态",
          key: "lotStatus",
          value: 0,
          options: [
            {
              value: 0,
              label: "全部",
            },
            {
              value: 1,
              label: "在场",
            },
            {
              value: 2,
              label: "离场",
            },
          ],
        },
        {
          type: "input",
          label: "车牌号",
          key: "carNumber1",
          value: "",
        },
      ],
      tableHeight: "随便设置的字符串，只要是字符串，表格高度就会受控于外部样式",
      searchForm: {},
      tableData: [],
      tableLoading: false,
      pageInfo: {
        currPage: 1,
        pageSize: 10,
        total: 0,
      },
    };
  },
  mounted() {
    // this.getTableData();
  },
  methods: {
    async sortFun(obj) {
      console.log("---", obj);
      this.pageInfo.sortList = obj;
      if (obj == "") {
        return this.getTableData();
      }
      this.sortReq();
    },
    async sortReq() {
      console.log("this.searchForm", this.searchForm);

      this.loading = true;
      let res = await getSysSystemParamSort({
        currPage: this.pageInfo.currPage,
        pageSize: this.pageInfo.pageSize,
        sortList: this.pageInfo.sortList,
        ...this.searchForm,
      });
      this.tableData = res.data.bdata.gdata;
      this.pageInfo.total = res.data.bdata.total;
      this.loading = false;
    },
    // 获取表格数据
    async getTableData() {
      this.tableLoading = true;
      // 没有排序条件
      let obj = {
        currPage: this.pageInfo.currPage,
        pageSize: this.pageInfo.pageSize,
        ...this.searchForm,
      };
      if (obj.sortStr == "") {
        delete obj.sortStr;
      } else {
        // 有排序条件
        obj.sortStr = this.searchForm.sortStr;
      }
      let sortList = "";
      sortList = this.tableColumns
        .filter((item) => item.sortType)
        .map((item) => {
          return {
            sortName: item.prop,
            sortType: item.sortType,
            sortStr,
          };
        });
      let sortStr = "";
      sortList.forEach((element, index) => {
        sortStr += `&sortList[${index}].sortName=${element.sortName}&sortList[${index}].sortType=${element.sortType}`;
      });
      obj.sortStr = sortStr;
      let res = await getSysSystemParam(obj);
      if (res.data && res.data.bdata.total > 0) {
        this.tableData = res.data.bdata.gdata;
        this.pageInfo.total = res.data.bdata.total;
      } else {
        this.tableData = [];
        this.pageInfo.total = 0;
      }
      this.tableLoading = false;
    },
    onReset(searchForm) {
      console.log("重置", searchForm);
      this.pageInfo.currPage = 1;
      // this.searchForm = searchForm;
      this.onQuery(searchForm);
    },
    onQuery(searchForm) {
      console.log("查询", searchForm);
      this.searchForm = searchForm;
      this.getTableData();
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageInfo.pageSize = val;
      this.getTableData();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.pageInfo.currPage = val;
      this.getTableData();
    },
    onSubmit() {
      console.log("submit!");
    },
    handleNodeClick(data) {
      console.log(data);
    },
    handleClick(row) {
      console.log(row);
    },
    //树节点筛选
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
  },
};
</script>
<style scoped></style>
